<template>
  <div class="box">
    <!--头部-->
    <header>
      <div class="page_shuoming">
        <el-header style="height: 110px;background-color: white">
          <div class="permission_text">门店调拨</div>
          <div class="Breadcrumb"><span>首页</span><span>/</span><span>门店调拨</span></div>
        </el-header>
      </div>
    </header>


    <!--表格-->
    <div class="table_pad">
      <el-main style="height: 700px;width:98%; background-color: white">
        <!--main的名字-->
        <div><span class="subhead">门店调拨</span></div>
        <div class="line"></div>
        <div class="button-area">
          <el-button @click="create_chailiao" type="primary">创建门店调拨</el-button>
          <el-button type="success" @click="search">&nbsp;&nbsp;查询&nbsp;&nbsp;</el-button>
          <el-button type="info" @click="addData">导出报表</el-button>
        </div>
        <!--tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)-->


        <!--创建商品拆料-->
        <div class="select" style="background-color: white;margin-top: 10px" v-if="!material_list">
          <h2>新建调拨</h2>
          <table>
            <tr>
              <td>
                <el-select v-model="leixing_value" style="width: 200px" placeholder="商品类型">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select v-model="chukumendian_val" style="width: 200px" placeholder="出库门店">
                  <el-option
                    v-for="item in chukumendian"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select v-model="chukuguitai_val" style="width: 200px" placeholder="出库柜台">
                  <el-option
                    v-for="item in chukuguitai"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input placeholder="创单日期" v-model="chuangdanriqi"></el-input>
              </td>
              <td>
                <el-input placeholder="单据编号" v-model="danjubianhao"></el-input>
              </td>
              <td>
                <button class="select_chailiao" @click="select_chailiao">选择商品</button>
                <button class="wancheng_chailiao" @click="wancheng_chailiao">完成选择</button>
              </td>
            </tr>
          </table>
        </div>


        <!--创建商品中的选择拆料点击后显示的商品库存统计列表-->
        <el-table
          :data="kucuntongji.slice((currentPage1-1)*pageSize1,currentPage1*pageSize1)"
          border
          style="width: 100%"
          v-if="chailiao_click_kucunshow"
          v-loading="loading"
          @selection-change="tongji_chailiao_changeFun"
        >
          <el-table-column type="selection" width="55" align="center" fixed></el-table-column>
          <el-table-column v-for="item in TongjitableName" :prop="item.prop" :label="item.label" width="100"
                           align="center">
          </el-table-column>
        </el-table>

        <!--分页-->
        <div class="block">
          <el-pagination v-if="chailiao_click_kucunshow"
                         @current-change="handleCurrentChange1"
                         @size-change="handleSizeChange1"
                         :current-page="currentPage1"
                         :page-sizes="[1, 2, 3, 4]"
                         :page-size="pageSize1"
                         layout="total, sizes, prev, pager, next, jumper"
                         :total="kucuntongji.length">
          </el-pagination>
        </div>

        <!--查询框-->
        <div class="select" style="background-color: white;margin-top: 10px" v-if="chaxun">
          <h2>查询</h2>
          <table>
            <tr>
              <td>
                <el-select v-model="leixing_value" style="width: 200px" placeholder="商品类型">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select v-model="chukumendian_val" style="width: 200px" placeholder="出库门店">
                  <el-option
                    v-for="item in chukumendian"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select v-model="chukuguitai_val" style="width: 200px" placeholder="出库柜台">
                  <el-option
                    v-for="item in chukuguitai"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <button class="select_chailiao" @click="click_sreach">点击搜索</button>
                <button class="wancheng_chailiao" @click="click_shouqi">收起</button>
              </td>
              <td></td>
            </tr>
          </table>
        </div>

        <!--拆料首页列表-->
        <el-table
          :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
          border
          style="width: 100%"
          v-if="material_list"
          v-loading="loading_chailiaolist"
          @selection-change="chailiao_changeFun"
        >
          <el-table-column type="selection" width="55" align="center" fixed></el-table-column>
          <el-table-column v-for="item in tableName" :prop="item.prop" :label="item.label" width="100" align="center">

          </el-table-column>
          <template>
            <el-table-column
              prop="操作"
              label="操作"
              width="300" align="center"
              fixed="right">
              <template slot-scope="scope">
                <el-button type="info" v-if="chexiao_shenpi_id.indexOf(scope.row.id)==-1&&quanxianshenhe" title="审核" size="mini"
                           @click="handleClick_shenpi(scope.row);openTanChuang_shenpi()"
                           :disabled="shenpi_id.indexOf(scope.row.id)!=-1">审核
                </el-button>
                <!--chexiao_bohui(scope.row.id);-->
                <el-button type="info" v-if="chexiao_shenpi_id.indexOf(scope.row.id)!=-1&&quanxianshenhe"
                           @click="chexiao_open(scope.row.id)" title="撤消驳回" size="mini">撤消驳回
                </el-button>
                <el-button type="primary" @click="handleClick_edit(scope.row);openTanChuang_edit()" v-if="edit_Features" size="mini">编辑
                </el-button>
                <el-button type="danger" title="" size="mini" @click="shanchu_open(scope.row.id)"
                           v-if="shenpi_id.indexOf(scope.row.id)==-1&&delete_Features">删除
                </el-button>
                <el-button type="primary" size="mini" @click="chailiaomingxi(scope.row.id);openTanChuang_mingxi()"
                           v-if="shenpi_id.indexOf(scope.row.id)!=-1">明细
                </el-button>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <!--分页-->
        <div class="block" v-if="material_list">
          <el-pagination
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"
            :current-page="currentPage"
            :page-sizes="[1, 2, 3, 5]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="tableData.length"
          >
          </el-pagination>
        </div>

      </el-main>


      <!--编辑弹窗-->
      <el-dialog title="编辑" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <table>
            <tr>
              <td class="shenpi_td_jian">行号:</td>
              <td class="shenpi_td_zhi">
                <el-input disabled v-model="form.id" autocomplete="off"
                          style="width: 150px;margin-left: 10px"></el-input>
              </td>
              <td class="shenpi_td_jian">单据编号:</td>
              <td class="shenpi_td_zhi">
                <el-input v-model="form.documentnum" autocomplete="off" style="width: 150px;margin-left: 10px"></el-input>
              </td>
              <td class="shenpi_td_jian">状态:</td>
              <td class="shenpi_td_zhi">
                <el-input disabled v-model="form.state" autocomplete="off"
                          style="width: 150px;margin-left: 10px"></el-input>
              </td>
            </tr>
            <tr>
              <td class="shenpi_td_jian">入库库类:</td>
              <td class="shenpi_td_zhi">
                <el-input v-model="form.inLibraryId" autocomplete="off"
                          style="width: 150px;margin-left: 10px"></el-input>
              </td>
              <td class="shenpi_td_jian">创单人:</td>
              <td class="shenpi_td_zhi">
                <el-input disabled v-model="form.createEid" autocomplete="off"
                          style="width: 150px;margin-left: 10px"></el-input>
              </td>
              <td class="shenpi_td_jian">审批人:</td>
              <td class="shenpi_td_zhi">
                <el-input disabled v-model="form.auditorEid" autocomplete="off"
                          style="width: 150px;margin-left: 10px"></el-input>
              </td>
            </tr>
            <tr>
              <td class="shenpi_td_jian">出库类库:</td>
              <td class="shenpi_td_zhi">
                <el-input v-model="form.outLibraryId" autocomplete="off"
                          style="width: 150px;margin-left: 10px"></el-input>
              </td>
              <td class="shenpi_td_jian">入库门店/总部:</td>
              <td class="shenpi_td_zhi">
                <el-input v-model="form.inStoreId" autocomplete="off" style="width: 150px;margin-left: 10px"></el-input>
              </td>
              <td class="shenpi_td_jian">出库门店/总部:</td>
              <td>
                <el-input v-model="form.outStoreId" autocomplete="off"
                          style="width: 150px;margin-left: 10px"></el-input>
              </td>
            </tr>
          </table>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="closeTanChuang_edit">取 消</el-button>
          <el-button type="primary" @click="closeTanChuang_edit();queren_edit()">确 定</el-button>
        </div>
      </el-dialog>


      <!--审批弹窗-->
      <el-dialog class="shenpi" title="审批" style="color: #409EFF" :visible.sync="dialogFormVisible_shenpi">
        <el-form :model="shenpi">
          <table>
            <tr>
              <td class="shenpi_td_jian">行号:</td>
              <td class="shenpi_td_zhi">{{shenpi.id}}</td>
              <td class="shenpi_td_jian">单据编号::</td>
              <td class="shenpi_td_zhi">{{shenpi.documentnum}}</td>
              <td class="shenpi_td_jian">状态:</td>
              <td class="shenpi_td_zhi">{{shenpi.state}}</td>
            </tr>
            <tr>
              <td class="shenpi_td_jian">创单日期:</td>
              <td class="shenpi_td_zhi">{{shenpi.auditTime}}</td>
              <td class="shenpi_td_jian">入库库类:</td>
              <td class="shenpi_td_zhi">{{shenpi.inLibraryId}}</td>
              <td class="shenpi_td_jian">传单人:</td>
              <td class="shenpi_td_zhi">{{shenpi.createEid}}</td>
            </tr>
            <tr>
              <td class="shenpi_td_jian">出库名称:</td>
              <td class="shenpi_td_zhi">{{shenpi.outStoreId}}</td>
              <td class="shenpi_td_jian"></td>
              <td class="shenpi_td_zhi"></td>
              <td></td>
              <td></td>
            </tr>
            <tr>
              <td>
                <el-button size="mini">查看具体商品</el-button>
              </td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
          </table>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="closeTanChuang_shenpi();shenpi_tongguo(shenpi.id,shenpi.state)">通过</el-button>
          <el-button type="danger" @click="closeTanChuang_shenpi();shenpi_bohui(shenpi.id,shenpi.state)">驳回</el-button>
          <el-button type="info" @click="closeTanChuang_shenpi()">取消</el-button>
        </div>
      </el-dialog>


      <!--编辑弹窗-->
      <el-dialog title="拆料明细" :visible.sync="dialogFormVisible_mingxi">
        <el-form :model="chailiaomingxi_list">
          <!--活动名称:-->
          <!--<el-input v-model="chailiaomingxi_list.name" autocomplete="off" style="width: 150px;margin-left: 10px"></el-input>-->
          <!--活动名称:-->
          <!--<el-input v-model="form.name" autocomplete="off" style="width: 150px;margin-left: 10px"></el-input>-->
          <h1>暂无数据</h1>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="closeChuang_mingxi">确 定</el-button>
        </div>
      </el-dialog>

    </div>
  </div>
</template>

<script>
    export default {
        name: "store_transfer",
      data() {
        return {
          tableData: [],
          kucuntongji: [],
          tableName: [
            {prop: "id", label: "行号"},
            {prop: "state", label: "状态"},
            {prop: "documentnum", label: "单据编号"},
            {prop:"auditTime",label:"创单日期",},
            {prop: "inLibraryId.name", label: "入库类库"},
            {prop: "outLibraryId.name", label: "出库类库"},
            {prop: "outStoreId.storeName", label: "出库门店/总部"},
            {prop: "inStoreId.storeName", label: "入库门店/总部"},
            {prop: "outCountId.name", label: "出库柜台"},
            {prop: "inCountId.name", label: "入库柜台"},
            {prop: "createEid.employee_user_name", label: "创单人"},
            {prop: "auditorEid.employee_user_name", label: "审批人"},
          ],
          loading: true,
          loading_chailiaolist: true,
          //商品统计的tableName
          TongjitableName: [
            {prop: "hanghao", label: "行号"},
            {prop: "weight", label: "重量"},
            {prop: "status", label: "状态"},
            {prop: "danjubianhao", label: "单据编号"},
            {prop: "zongbumingcheng", label: "总部名称"},
            {prop: "fendian", label: "分店"},
            {prop: "leikumingcheng", label: "类库名称"},
            {prop: "shuliang", label: "数量"},
            {prop: "chuangdanriqi", label: "创单日期"}
          ],

          //分页
          currentPage: 1,
          pageSize: 3,
          currentTotal: 0,
          //创建商品中的选择拆料点击后显示的商品库存统计列表
          currentPage1: 1,
          pageSize1: 3,
          currentTotal1: 0,
          //表格显示隐藏
          material_list: true,
          options: [
            {
              value: '素金类',
              label: '素金类'
            },
            {
              value: '镶嵌类',
              label: '镶嵌类'
            }],
          leixing_value: '',
          chukumendian: [
            {
              value: '成都门店',
              label: '成都门店'
            },
            {
              value: '四川门店',
              label: '四川门店'
            }
          ],
          chukumendian_val: '',
          chukuguitai_val: "",
          chukuguitai: [
            {
              value: '柜台1',
              label: '柜台1'
            },
            {
              value: '柜台2',
              label: '柜台2'
            }
          ],
          chuangdanriqi: "",
          danjubianhao: "",
          chailiao_click_kucunshow: false,
          //拆料页面多选数组
          multipleSelection: [],
          //商品统计的多选数组
          tongji_multipleSelection: [],
          // dialogTableVisible: false,
          dialogFormVisible: false,
          dialogFormVisible_shenpi: false,

          //编辑时的数据
          form: {
         id:"",
         documentnum:"",
         auditTime:"",
         inLibraryId:"",
         outLibraryId:"",
         outStoreId:"",
         inStoreId:"",
         outCountId:"",
         inCountId:"",
         createEid:"",
         auditorEid:"",
            state:""
          },
          formLabelWidth: '100px',
          //审批弹窗数据
          //将键换为当前页面需要展示的数据名称
          shenpi: {
            id:"",
            documentnum:"",
            state: "",
            auditTime:"",
            outLibraryId: "",
            inLibraryId: "",
            createEid: "",
            outStoreIdL:"",
            leikumingcheng: "",
            shuliang: "",
          },
          shenpi_id: [1],
          chexiao_shenpi_id: [],
          chaxun: false,
          dialogFormVisible_mingxi: false,
          chailiaomingxi_list: {
            hanghao: '',
            weight: "",
            status: "",
            danjubianhao: "",
            zongbumingcheng: "",
            fendian: "",
            leikumingcheng: "",
            shuliang: "",
            id: ""
          },
          quanxianshenhe: true,
          delete_Features: true,
          edit_Features:true
        }
      },


      // store,



      //页面加载时获取门店调拨列表
      // created() {
      //   this.loading_chailiaolist = true;
      //   // this.$axios.get(this.$api.commodity_material.Material_list).then((res) => {
      //       this.$axios.post("http//172.16.6.56:8080/findStoreAllocation",
      //         {
      //           transformRequest: [
      //             function (data) {
      //               let params = "";
      //               var arr = [];
      //               for (var key in data) {
      //                 arr.push(key + "=" + data[key]);
      //               }
      //               params = arr.join("&");
      //               return params;
      //             }
      //           ]
      //         }, {
      //           headers: {
      //             'Content-Type': 'application/x-www-form-urlencoded'
      //           }
      //         }).then((res) => {
      //         console.log(res);
      //         if (res.data.tableData) {
      //       this.tableData = res.data.tableData;
      //       this.loading_chailiaolist = false;
      //     }
      //   });
      //   this.anniu_quanxian();
      // },
      beforeMount(){
        this.loading_chailiaolist = true;
        this.$axios.post("http://172.16.6.56:8080/findStoreAllocation",
          {
            transformRequest: [
              function (data) {
                let params = "";
                var arr = [];
                for (var key in data) {
                  arr.push(key + "=" + data[key]);
                }
                params = arr.join("&");
                return params;
              }
            ]
          }, {
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          })
          .then((res) => {
            console.log(res.data.data.inventoryChangelist);
            if (res.data.data.inventoryChangelist) {
              this.tableData = res.data.data.inventoryChangelist;
              for(var i = 0;i<res.data.data.inventoryChangelist.length;i++){
                var d = new Date(res.data.data.inventoryChangelist[i].auditTime);
                this.tableData[i].auditTime = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDay();
                var a = this.tableData[i].state;
                if(a = 3){
                  this.tableData[i].state = "已变更";
                }else if(a = 2){
                  this.tableData[i].state = "已驳回";
                }else if(a = 1){
                  this.tableData[i].state = "已通过";
                }else if(a = 0){
                  this.tableData[i].state = "待审批";
                }
              }
              this.loading_chailiaolist = false;
            }
          }).catch((err) => {
          console.log(err);
        })
      },

      methods: {
        addData(){
          let data={
            id:1
          };
          this.$axios.post(this.$api.commodity_material.test,data,
            {
              transformRequest: [
                function (data) {
                  let params = "";
                  var arr = [];
                  for (var key in data) {
                    arr.push(key + "=" + data[key]);
                  }
                  params = arr.join("&");
                  return params;
                }
              ]
            }, {
              headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
              }
            }).then((res) => {
            console.log(res);
          });
        },

        //获取审核按钮权限
        anniu_quanxian(){
          //每个页面id固定,每次加载时根据用户列表信息里的id来查找是否用户此功能
          let index = this.$store.state.user.menuInfo[0].header.findIndex((item)=>{
            return item.id===1;
          });
          //审核权限
          this.quanxianshenhe=this.$store.state.user.menuInfo[0].header[index].review_anniu;
          //删除权限
          this.delete_Features = this.$store.state.user.menuInfo[0].header[index].delete_Features;
          //编辑权限
          this.edit_Features = this.$store.state.user.menuInfo[0].header[index].edit_Features;
          // console.log(this.quanxianshenhe);
          // console.log(this.delete_Features);
          // console.log(this.edit_Features);
        },

        //获取列表数据
        // getIndexList() {
        //   this.loading_chailiaolist = true;
        //   this.$axios.get("http:172.16.6.69:8080/page/selectProductReturnByEmployeeId"
        //
        //   ).then((res) => {
        //     if (res.data.tableData) {
        //       this.tableData = res.data.tableData;
        //       this.loading_chailiaolist = false;
        //     }
        //   })
        // },

        handleSizeChange(val) {
          this.pageSize = val;
          // console.log(`每页 ${val} 条`);
          //每次动态更新条数
        },
        handleCurrentChange(val) {
          this.currentPage = val;
          console.log(111 + "当前第:" + val);
        },

        //-创建商品中的选择拆料点击后显示的商品库存统计列表
        handleSizeChange1(val) {
          this.pageSize1 = val;
          // console.log(`每页 ${val} 条`);
          //每次动态更新条数
        },

        //查询商品分页获取当前页
        handleCurrentChange1(val) {
          this.currentPage1 = val;
        },

        //创建拆料
        create_chailiao() {
          //隐藏首页数据显示,并且展示商品统计页面数据,并且显示商品统计的分页div
          this.material_list = false;
          this.chaxun = false;
        },

        //测试
        dianji(data) {
          console.log(data)
        },
        //撤消驳回提示框
        chexiao_open(scope_row_id) {
          this.$confirm('是否撤消驳回?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(() => {
            this.chexiao_bohui(scope_row_id);
            this.$message({
              type: 'success',
              message: '已撤销驳回!',
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '取消操作'
            });
          });
        },

        //删除提示框
        shanchu_open(scope_row_id) {
          this.$confirm('是否删除?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(() => {
            // console.log(scope_row_id)
            this.tableData_del(scope_row_id);
            this.$message({
              type: 'success',
              message: '删除成功!',
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '取消删除'
            });
          });
        },

        //创建拆料中点击选择拆料
        select_chailiao() {
          let canshu = {
            leixing_value: this.leixing_value,
            chukumendian_val: this.chukumendian_val,
            chuangdanriqi: this.chuangdanriqi,
            danjubianhao: this.danjubianhao
          };
          //参数直接加载下面  改为post请求
          //loading加载框
          this.loading = true;
          this.$axios.get(this.$api.commodity_material.Material_list)
            .then((res) => {
            if (res.data.kucuntongji) {
              this.kucuntongji = res.data.kucuntongji;
              this.loading = false;
            }
          });
          this.chailiao_click_kucunshow = true;
        },

        //完成拆料按钮
        wancheng_chailiao() {
          this.chailiao_click_kucunshow = false;
          this.material_list = true;
          console.log(this.tongji_multipleSelection);
        },

        //获取选中数组
        chailiao_changeFun(val) {
          let new_list = [];
          if (val.length > 0) {
            for (let i = 0; i < val.length; i++) {
              new_list.push(val[i].id);
            }
          }
          this.multipleSelection = new_list;
        },

        //选择拆料内的获取选中的数组
        tongji_chailiao_changeFun(val) {
          let new_list = [];
          if (val.length > 0) {
            for (let i = 0; i < val.length; i++) {
              new_list.push(val[i].id);
            }
          }
          this.tongji_multipleSelection = new_list;
        },

        //编辑时获取当前行的id
        handleClick_edit(row) {
          // {prop: "id", label: "行号"},
          // {prop: "documentnum", label: "单据编号"},
          // {prop:"auditTime",label:"创单日期",},
          // {prop: "inLibraryId.name", label: "入库类库"},
          // {prop: "outLibraryId.name", label: "出库类库"},
          // {prop: "outStoreId.storeName", label: "出库门店/总部"},
          // {prop: "inStoreId.storeName", label: "库门店/总部"},
          // {prop: "outCountId.name", label: "出库柜台"},
          // {prop: "inCountId.name", label: "入库柜台"},
          // {prop: "createEid.employee_user_name", label: "创单人"},
          // {prop: "auditorEid.employee_user_name", label: "审批人"},
          this.form.id = row.id;
          this.form.documentnum = row.documentnum;
          this.form.auditTime = row.auditTime;
          this.form.inLibraryId = row.inLibraryId.name;
          this.form.outLibraryId = row.outLibraryId.name;
          this.form.outStoreId = row.outStoreId.storeName;
          this.form.inStoreId = row.inStoreId.storeName;
          this.form.outCountId = row.outCountId.name;
          this.form.inCountId = row.inCountId.name;
          this.form.createEid = row.createEid.employee_user_name;
          this.form.auditorEid = row.auditorEid.employee_user_name;
          var a = row.state;
          if(a = 3){
            this.form.state = "已变更";
          }else if(a = 2){
            this.form.state = "已驳回";
          }else if(a = 1){
            this.form.state = "已通过";
          }else if(a = 0){
            this.form.state = "待审批";
          }
          console.log(row.state);


          // this.form.row.inLibraryId = row.inLibraryId.name
        },

        //审批时获取当前行id
        handleClick_shenpi(row) {
          this.shenpi.id=row.id;
          this.shenpi.documentnum=row.documentnum;
          this.shenpi.auditTime=row.auditTime;
          this.shenpi.inLibraryId=row.inLibraryId.name;
          this.shenpi.state=row.state;
          this.shenpi.createEid=row.createEid.employee_user_name;
          this.shenpi.outStoreId=row.outStoreId.storeName;
        },

        // 关闭编辑弹窗方法
        closeTanChuang_edit() {
          this.dialogFormVisible = false;
        },
        //打开编辑弹窗
        openTanChuang_edit() {
          this.dialogFormVisible = true;
        },
        //拆料明细弹窗
        openTanChuang_mingxi() {
          this.dialogFormVisible_mingxi = true;
        },
        //关闭拆料明细弹窗
        closeChuang_mingxi() {
          this.dialogFormVisible_mingxi = false;
        },
        // 关闭审批弹窗方法
        closeTanChuang_shenpi() {
          this.dialogFormVisible_shenpi = false;
        },
        //打开审批弹窗
        openTanChuang_shenpi() {
          this.dialogFormVisible_shenpi = true;
        },

        //审批通过
        shenpi_tongguo(id,state) {
          //1.将当前数据发送到后台,修改商品审批状态
          //2.前台将审核按钮变成禁用,并且删除按钮变为查看详情
          //动态生成
          // console.log(id);
          // console.log(state);

          let data={
            id:id,
            state:state
          }
          console.log(data.state);

          this.$axios.post("http://172.16.6.56:8080/updateDistributionRetrievalByState", data,
            {
              transformRequest: [
                function (data) {
                  let params = "";
                  var arr = [];
                  for (var key in data) {
                    arr.push(key + "=" + data[key]);
                  }
                  params = arr.join("&");
                  return params;
                }
              ]
            }, {
              headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
              }
            })
            .then((res) => {
              console.log(res);
              // console.log(a);
              // console.log(res);
            }).catch((err) => {
            // console.log(err);
          })
          this.shenpi_id.push(id);
          // console.log(this.shenpi_id);
          //页面将状态改为已通过
          let index = this.tableData.findIndex(function (item) {
            return item.id == id
          });
          this.tableData[index].status = "已通过"
        },

        //审批页面的驳回

        shenpi_bohui(id,state) {
          let data={
            id:id,
            state:state
          }
          this.$axios.post("http://172.16.6.56:8080/updateDistributionRetrievalByState", data,
            {
              transformRequest: [
                function (data) {
                  let params = "";
                  var arr = [];
                  for (var key in data) {
                    arr.push(key + "=" + data[key]);
                  }
                  params = arr.join("&");
                  return params;
                }
              ]
            }, {
              headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
              }
            })
            .then((res) => {
              console.log(res);
              // console.log(a);
              // console.log(res);
            }).catch((err) => {
            // console.log(err);
          })
          //动态生成 created中生成
          this.chexiao_shenpi_id.push(id);
          // console.log(this.chexiao_shenpi_id);
          let index = this.tableData.findIndex(function (item) {
            return item.id == id
          });
          this.tableData[index].status = "驳回"
        },

        //撤消驳回
        chexiao_bohui(id) {
          let index = this.chexiao_shenpi_id.indexOf(id);
          this.chexiao_shenpi_id.splice(index, 1);
          let chexiao_index = this.tableData.findIndex(function (item) {
            return item.id == id
          });
          this.tableData[chexiao_index].status = "待审核"
        },
        //删除方法
        tableData_del(id) {
          let index = this.tableData.findIndex(function (item) {
            return item.id == id
          });
          let data = {
            inventoryChangeId: this.tableData[index].id
          };
          this.tableData.splice(index, 1);
          console.log(data);
          this.$axios.post("http://172.16.6.56:8080/deleteStoreAllocation", data,
            {
              transformRequest: [
                function (data) {
                  let params = "";
                  var arr = [];
                  for (var key in data) {
                    arr.push(key + "=" + data[key]);
                  }
                  params = arr.join("&");
                  return params;
                }
              ]
            }, {
              headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
              }
            })
            .then((res) => {
              console.log(res.data.data);
              // console.log(res);
            }).catch((err) => {
            console.log(err);
          })

        },

        search() {
          //搜索栏显示,同时将创建栏隐藏
          this.chaxun = true;
          this.material_list = true;
          this.chailiao_click_kucunshow = false;
        },

        //点击搜索
        click_sreach() {
          //获取到用户搜索数据,向后台请求将tableDate数据换成请求回来的数据,点击收起将数据还原为初始状态
          let data = {
            shangpingleixing: this.leixing_value,
            chukumendian: this.chukumendian_val,
            chukuguitai: this.chukuguitai_val
          };
          console.log(data);
          //发起请求获取数据
          this.loading_chailiaolist = true;
          this.$axios.get(this.$api.commodity_material.Material_list).then((res) => {
            if (res.data.tableData) {
              this.tableData = res.data.tableData;
              this.loading_chailiaolist = false;
            }
          });
          //将数据清空,方便创建拆料查询商品使用
          this.leixing_value = this.chukumendian_val = this.chukuguitai_val = "";
        },
        //点击收起,搜索栏隐藏
        click_shouqi() {
          this.chaxun = false;
        },
        //编辑确认按钮
        queren_edit() {
          //获取到当前from,将数据提交到后台,前台可使用静态修改,减少不必要的数据请求
          let data = {};
          let id = this.form.id;
          // console.log(id);
          let index = this.tableData.findIndex(function (item) {
            return item.id == id;
          });

          // this.form.id = row.id;
          // this.form.documentnum = row.documentnum;
          // this.form.auditTime = row.auditTime;
          // this.form.inLibraryId = row.inLibraryId.name;
          // this.form.outLibraryId = row.outLibraryId.name;
          // this.form.outStoreId = row.outStoreId.storeName;
          // this.form.inStoreId = row.inStoreId.storeName;
          // this.form.outCountId = row.outCountId.name;
          // this.form.inCountId = row.inCountId.name;
          // this.form.createEid = row.createEid.employee_user_name;
          // this.form.auditorEid = row.auditorEid.employee_user_name;

          data = this.tableData[index];
          this.tableData[index].documentnum = this.form.documentnum;
          this.tableData[index].inLibraryId = {name:this.form.inLibraryId};
          this.tableData[index].outLibraryId = {name:this.form.outLibraryId};
          console.log(this.form.outLibraryId);


          this.tableData[index].outStoreId = {storeName:this.form.outStoreId};
          this.tableData[index].inStoreId = {storeName:this.form.inStoreId};
          // console.log(this.tableData[index].inStoreId);

          console.log(data);

          let dat = {
            ic_id: this.tableData[index].id,
            ic_receipt_number:this.tableData[index].documentnum,
            in_class_library_id:1,
            out_class_library_id:6,
            out_headquarters_store_id:3,
            in_headquarters_store_id:1,
          };
          console.log(dat);
          this.$axios.post("http://172.16.6.56:8080/updateStoreAllocation", dat,
            {
              transformRequest: [
                function (dat) {
                  let params = "";
                  var arr = [];
                  for (var key in dat) {
                    arr.push(key + "=" + dat[key]);
                  }
                  params = arr.join("&");
                  return params;
                }
              ]
            }, {
              headers: {
                'Content-Type': 'application/json'
              }
            })
            .then((res) => {
              console.log(res.data.data);
              console.log(res);
            }).catch((err) => {
            // console.log(err);
          })
        },
        //  拆料明细
        chailiaomingxi() {

        },

        getPageData() {
          console.log(1);
        }
      }
    }

</script>

<style scoped>
  .box {
    background-color: #f6f6f6;
    width: 85%;
    min-height: 600px;
  }

  .box td {
    padding: 8px 0;
  }

  .table_pad {
    margin-left: 20px;
    margin-top: 20px;
  }

  .permission_text {
    font-size: 30px;
    padding-top: 20px;
    padding-left: 15px;
  }

  .subhead {
    font-size: 24px;
  }

  .line {
    margin-top: 10px;
    margin-bottom: 30px;
    border-top: 1px solid #DADADA;
  }

  .Breadcrumb {
    font-size: 12px;
    margin-top: 10px;
    margin-left: 10px;
    color: #999999;
  }

  .Breadcrumb span {
    margin-left: 10px;
  }

  .Breadcrumb span:nth-of-type(1) {
    color: #3380FF;
  }

  .button-area {
    padding-left: 10px;
    margin-bottom: 10px;
  }

  .select h2 {
    font-size: 18px;
    font-weight: 400;
    margin-left: 5px;
  }

  .select table {
    width: 100%;
  }

  .select td {
    width: 17%;
    height: 40px;
    /*border: 1px solid red;*/
  }

  .select select {
    width: 100px;
    height: 20px;
  }

  .select_chailiao,
  .wancheng_chailiao {
    margin-left: 10px;
    width: 70px;
    height: 39px;
    outline: none;
    border: 1px solid #eee;
    background-color: #409EFF;
    font-size: 13px;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
  }

  .select_chailiao:hover {
    background-color: #66b1ff;
  }

  .wancheng_chailiao:hover {
    background-color: #85ce61;
  }

  .wancheng_chailiao {
    background-color: #67c23a;
  }

  .table-area {
    margin-top: 10px;
  }

  .shenpi_td_jian {
    width: 70px;
    text-align: right;
    font-size: 14px;
    color: #8C8B8D;
  }

  .shenpi tr > td {
    padding-left: 22px;
  }

  .shenpi_td_zhi {
    width: 110px;
    padding-left: 15px;
    font-size: 16px;
  }
</style>
